  <div class="admin_title">
   <h2>chat配置</h2>
   <a class="right button" href="javascript:history.back(-1)">返回上一页</a>
  </div>
  <div class="form_box">
        <table width="100%">  
            <tr>
              <th>服务操作：</th>
                <td>
                  <input class="button" type="button" onclick="execServer('start');" value="开启">　<input class="button" type="button" onclick="execServer('stop');" value="关闭">　<input class="button" type="button" onclick="execServer('restart');" value="重启">
                </td>
              
              <td>(手动开启、关闭、重启服务，若环境开启了安全模式则没用)</td>
            </tr>
             <tr>
              <th>通信状态：</th>
                <td>
                  <span id="state"><span>  
                </td>
              
              <td>(与node.js的通信,若失败，请确认服务是否运行，或ip与端口号是否正确)</td>
            </tr>
            <tr>
              <th>redis服务：</th>
                <td>
                  <input class="button" type="button" onclick="execRedisServer('start');" value="开启">　<!--input class="button" type="button" onclick="execRedisServer('stop');" value="关闭">　<input class="button" type="button" onclick="execRedisServer('restart');" value="重启"><span--> 
                </td>
              
              <td>(手动开启、关闭、重启服务，若环境开启了安全模式则没用，用于漫游存储记录)</td>
            </tr>
           
            <tr>
              <th>服务器IP：</th>
                <td>
                  <input type="text" name="ip" id="ip" value="{$data['ip']}"/>  
                
                </td>
              
              <td>(或域名,若在同一服务器127.0.0.1 即可,配置好后，一般不需要修改)</td>
            </tr>
            
            <tr>
              <th>chat端口：</th>
                <td>
                  <input type="text" name="port" id="port" value="{$data['port']}"/>  
                
                </td>
              
              <td>(chat端口号，不要用80等常见端口)</td>
            </tr>
            
            <tr>
              <th>回调地址：</th>
                <td>
                  <input type="text" class="w300" name="callback" id="callback" value="{$data['callback']}"/>  
                
                </td>
              
              <td>(即chat页面,带http://)</td>
            </tr>
            
						<tr>
              <th>公共文件目录：</th>
                <td>
                  <input type="text" class="w300" name="pub" id="pub" value="{$data['pub']}"/>  
                
                </td>
              
              <td>(带域名的public目录路径，如：www.canphp.com/public)</td>
            </tr>
						
            <tr>
              <th>公共文件绝对地址：</th>
                <td>
                  <input type="text" class="w300" name="pub2" id="pub2" value="{$data['pub2']}"/>  
                
                </td>
              
              <td>(物理路径的绝对地址，如d:/wamp/web/cpapp/public,主要用于自动开启服务)</td>
            </tr>
            
            <tr>
              <th>chat窗口宽：</th>
                <td>
                  <input type="text" name="w" id="w" value="{$data['w']}"/>  
                
                </td>
              
              <td>(聊天对话框的宽度, 空或0自适应)</td>
            </tr>
            
            <tr>
              <th>chat窗口高：</th>
                <td>
                  <input type="text" name="h" id="h" value="{$data['h']}"/>  
                
                </td>
              
              <td>(聊天对话框的高度, 空或0自适应)</td>
            </tr>
            
            <tr>
              <th>显示位置：</th>
              <td><input type="radio" name="radio" {if $data['p']=='tleft'}checked{/if} id="tleft" /> 左上  &nbsp;&nbsp;<input type="radio" name="radio" {if $data['p']=='dleft'}checked{/if} id="dleft" /> 左下 &nbsp;&nbsp;
                  <input type="radio" name="radio" {if $data['p']=='tright'}checked{/if} id="tright" /> 右上 &nbsp;&nbsp; <input type="radio" name="radio" {if $data['p']=='dright'}checked{/if} id="dright" /> 右下&nbsp;&nbsp;
                  <input type="radio" name="radio" {if $data['p']=='left'}checked{/if} id="left" /> 左中  &nbsp;&nbsp;<input type="radio" name="radio" {if $data['p']=='right'}checked{/if} id="right" /> 右中&nbsp;&nbsp;
              </td>
              <td>(前台图标显示位置)</td>
            </tr>
            <tr>
              <th>&nbsp;</th>
              <td align="center"><input class="button" onclick="getScript();" href="javascript:void(0);" value="确定并更新缓存" type="button" name="dosubmit" />
              </td>
              <td>(将代码放在页面最底部)</td>
            </tr>
            
        </table>
     
    </div>
  <script type="text/javascript">
		$(function(){
			chatServer();
		});
    
    function execServer(t){
      $.ajax({
				url : "{url('chat/index/execServer')}",
				data : 't='+t,
        type : 'POST',
				success : function(data){
					
				}
				
			});
      chatServer();
    }
    function execRedisServer(t){
      $.ajax({
				url : "{url('chat/index/execRedisServer')}",
				data : 't='+t,
        type : 'POST',
				success : function(data){
					
				}
				
			});
    }
    
    function chatServer(){
      $('#state').html('正在检测状态...');
      $.ajax({
				url : "{url('chat/index/getStatue')}",
				timeout : 10000, 
				dataType : 'json', 
				success : function(data){
					$('#state').html(data.state);
				}, 
				error : function(){
					$('#state').html('<font color="red">通信失败，请确定配置是否正确或服务是否开启</font>');
				}
			});
    }
    
    function getScript() {
      var ip = $('#ip').val();
      var port = $('#port').val();
      var callback = $('#callback').val();
      var pub = $('#pub').val();
      var pub2 = $('#pub2').val();
      var w = $('#w').val();
      var h = $('#h').val();
      var pos = ['tleft', 'dleft', 'tright', 'dright', 'left', 'right'];
      for(var i in pos) {
        if($('#'+pos[i]).attr("checked")) {
          var p = pos[i];
          break;
        }
      }
      var dialog = art.dialog({id:'xxx', title:'chat配置', content:''});
      if(ip == ''){ dialog.content('服务器ip不能为空'); return false;}
      if(port == '') {dialog.content('chat端口不能为空'); return false;}
      if(callback == '') {dialog.content('回调地址不能为空'); return false;}
      //if(w == '') {dialog.content('宽度不能为空'); return false;}
      //if(h == '') {dialog.content('高度回调地址不能为空'); return false;}
      if(pub == '') {dialog.content('公共文件路径不能为空'); return false;}
      if(pub2 == '') {dialog.content('公共文件物理路径不能为空'); return false;}
      dialog.content('正在生成代码...').lock(true);
      $.ajax({
        url : "{url('chat/index/getScript')}",
        data : 'port='+port+'&p='+p+'&ip='+ip+'&callback='+callback+'&w='+w+'&h='+h+'&pub='+pub+'&pub2='+pub2,
        type : 'POST',
        success : function(data) {
          dialog.content(data);
        }
      });
    }
  </script>